
from app import celery_app
from app.db.models.jobs import Job
from app.db.models.balances import Balances
from app.libs.utils import balance_task_count_sync


@celery_app.task(acks_late=True)
def sync_user_balances(uid: str = None, job_id: str = None):
    """同步用户套餐信息
    domain
    domainEnable
    httpMaxTask
    pingMaxTask
    httpMaxTaskEnable
    pingMaxTaskEnable

    Args:
        uid ([type], optional): [用户id]. Defaults to None.
        job_id ([type], optional): [资产id]. Defaults to None.

    """
    if not uid and not job_id:
        return

    if uid:
        pass
    elif job_id:
        if job := Job.objects.with_id(job_id):
            uid = job.uid
        else:
            return
    else:
        return
    balance = Balances.objects.filter(uid=uid).first()
    # 统一使用balance_task_count_sync处理
    balance_task_count_sync(uid, balance)
